home *** CD-ROM | disk | FTP | other *** search
- #
- # addressBook.py
- # JunkMatcher
- #
- # Created by Benjamin Han on 2/1/05.
- # Copyright (c) 2005 Benjamin Han. All rights reserved.
- #
-
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; either version 2
- # of the License, or (at your option) any later version.
-
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
-
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- #!/usr/bin/env python
-
- from consts import *
-
- import sets
- import AddressBook
-
-
- def getAddressesFromABook ():
- """(MAC OS X ONLY) Returns a set of email addresses, excluding a user's own email addresses."""
- book = AddressBook.ABAddressBook.sharedAddressBook()
- me = book.me() # can be None
- if me:
- people = filter(lambda p:p is not me, book.people())
- else:
- people = book.people()
-
- return reduce(lambda x, y: x | y,
- map(lambda emails: sets.Set(map(lambda i: emails.valueAtIndex_(i).lower(), range(emails.count()))),
- filter(lambda emails: emails,
- map(lambda p: p.valueForProperty_(u'Email'), people))),
- sets.Set())
-
- ## ret = sets.Set()
- ## for emails in filter(lambda emails: emails, map(lambda p: p.valueForProperty_(u'Email'), people)):
- ## ret |= sets.Set(map(lambda i: emails.valueAtIndex_(i).lower(), range(emails.count())))
-
- ## for p in people:
- ## emails = p.valueForProperty_(u'Email')
- ## if emails:
- ## ret |= sets.Set(map(lambda i: emails.valueAtIndex_(i).lower(), range(emails.count())))
-
- ## return ret
-
-
- if __name__ == '__main__':
- addrs = getAddressesFromABook()
- print addrs
-